Load libraries (packages)

library("respR") ## respirometry/slope analysis
library("tidyverse") ## data manipulation

Set working directory

setwd("[PATH TO DIRECTORY]")

System1 - Dell

Importing data from firesting for resting

preexperiment_date <- "28 June 2023 11 39AM/All"
postexperiment_date <- "28 June 2023 04 01PM/All"

##--- last fish run in trial ---##
experiment_date <- "28 June 2023 12 42PM/Oxygen"
experiment_date2 <- "28 June 2023 12 42PM/All"

firesting <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1 <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date2,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

System2 - Asus

Importing data from firesting for resting

preexperiment_date_asus <- "28 June 2023 11 46AM/All"
postexperiment_date_asus <- "28 June 2023 04 43PM/All"

##--- last fish run in trial ---##
experiment_date_asus <- "28 June 2023 01 33PM/Oxygen"
experiment_date2_asus <- "28 June 2023 01 33PM/All"

firesting_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last_asus <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Chamber volumes

chamber1_dell = 0.04650#+0.00022
chamber2_dell = 0.04593#+0.00022
chamber3_dell = 0.04977#+0.00022
chamber4_dell = 0.04860#+0.00022

chamber1_asus = 0.04565
chamber2_asus = 0.04573#+0.00385
chamber3_asus = 0.04551#+0.00322
chamber4_asus = 0.04791#+0.00277

Date_tested="2023-06-28"
Clutch = "129" 
Male = "CVLA486" 
Female = "CVLA463"
Population = "Vlassof"
Tank =216 
salinity =36 
Date_analysed = Sys.Date() 

Replicates

1

Enter specimen data

Replicate = 1 
mass = 0.0007269
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "28 June 2023 12 24PM/Oxygen"
experiment_mmr_date2 <- "28 June 2023 12 24PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0002369004

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001973618

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.49
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1] 10 11 14 15 16 18 19 23 24 29 30 31 32 33 36 37 38 39 40 41
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.17
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     197.6021 -0.01801401 0.989      NA 1636   1891  5491.16
## 2:   5    1     209.1604 -0.01832606 0.993      NA 2176   2431  6031.16
## 3:  11    1     281.5854 -0.01974910 0.982      NA 5416   5671  9271.16
## 4:  12    1     293.3269 -0.01980200 0.976      NA 5956   6211  9811.16
## 5:  14    1     281.1889 -0.01674526 0.990      NA 7036   7291 10891.16
## 6:  15    1     312.6198 -0.01869474 0.979      NA 7576   7831 11431.16
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  5746.16 98.428 93.847 -0.01801401 -0.0001151217   -0.01789889 -0.01789889
## 2:  6286.16 98.581 93.732 -0.01832606 -0.0002226604   -0.01810340 -0.01810340
## 3:  9526.16 98.030 93.090 -0.01974910 -0.0008678929   -0.01888121 -0.01888121
## 4: 10066.16 98.589 93.635 -0.01980200 -0.0009754316   -0.01882657 -0.01882657
## 5: 11146.16 98.473 94.168 -0.01674526 -0.0011905091   -0.01555475 -0.01555475
## 6: 11686.16 98.582 93.494 -0.01869474 -0.0012980479   -0.01739669 -0.01739669
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.2032950
## 2:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.2056179
## 3:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.2144522
## 4:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.2138316
## 5:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.1766704
## 6:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.1975911
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -279.6740          NA  mgO2/hr/kg   -279.6740
## 2:   -282.8695          NA  mgO2/hr/kg   -282.8695
## 3:   -295.0230          NA  mgO2/hr/kg   -295.0230
## 4:   -294.1692          NA  mgO2/hr/kg   -294.1692
## 5:   -243.0463          NA  mgO2/hr/kg   -243.0463
## 6:   -271.8270          NA  mgO2/hr/kg   -271.8270
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 1 CVLA486 CVLA463 Vlassof 216 0.0007269 ch4 Dell7440 0.0486 2023-06-28 2024-08-16 good/good 36 27 284.7125 0.2069575 0.9838

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.49
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  4  5  6  7  8 10 16 19 20 21 27 28 29 30 31 32 33 35
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.07
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     250.0163 -0.05325798 0.9964561      NA   165    225
##   2:    NA     2     249.7347 -0.05316218 0.9962047      NA   166    226
##   3:    NA     3     249.3541 -0.05303670 0.9958497      NA   164    224
##   4:    NA     4     249.0557 -0.05293348 0.9958283      NA   167    227
##   5:    NA     5     248.3518 -0.05270107 0.9948851      NA   163    223
##  ---                                                                    
## 237:    NA   237     180.8279 -0.02972111 0.9519758      NA    96    156
## 238:    NA   238     180.3499 -0.02954827 0.9547633      NA    92    152
## 239:    NA   239     180.2697 -0.02952662 0.9543032      NA    95    155
## 240:    NA   240     179.7903 -0.02935944 0.9560828      NA    94    154
## 241:    NA   241     179.7652 -0.02934861 0.9562104      NA    93    153
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 2946.38 3006.38 93.013 89.948 -0.05325798
##   2: 2947.39 3007.39 93.042 89.990 -0.05316218
##   3: 2945.38 3005.38 92.959 89.974 -0.05303670
##   4: 2948.39 3008.39 93.063 89.942 -0.05293348
##   5: 2944.38 3004.38 92.961 90.019 -0.05270107
##  ---                                          
## 237: 2877.49 2937.49 95.456 93.249 -0.02972111
## 238: 2873.50 2933.50 95.643 93.557 -0.02954827
## 239: 2876.49 2936.49 95.492 93.324 -0.02952662
## 240: 2875.49 2935.49 95.507 93.411 -0.02935944
## 241: 2874.48 2934.48 95.588 93.556 -0.02934861
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.05325798
## Adjustment    : 0.0002369004
## Adjusted Rate : -0.05349488 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 241 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 240 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     250.0163 -0.05325798 0.9964561      NA 165    225 2946.38
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 3006.38 93.013 89.948 -0.05325798 0.0002369004   -0.05349488 -0.05349488
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0007269   NA 36 27 1.013253 -0.6075933
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -835.8692          NA  mgO2/hr/kg   -835.8692
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 1 CVLA486 CVLA463 Vlassof 216 0.0007269 ch4 Dell7440 0.0486 2023-06-28 2024-08-16 good/good 36 27 284.7125 0.2069575 0.9838 835.8692 0.6075933 0.9964561 551.1566 0.4006357

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 350 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

2

Enter specimen data

Replicate = 2 
mass = 0.0005405 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "28 June 2023 12 33PM/Oxygen"
experiment_mmr_date2 <- "28 June 2023 12 33PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0004699868

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post
## [1] -0.006248105

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.49
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1] 10 11 14 15 16 18 19 23 24 29 30 31 32 33 36 37 38 39 40 41
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.17
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   5    1     179.3632 -0.01322641 0.980      NA 2176   2431  6031.16
## 2:   6    1     186.5356 -0.01326130 0.979      NA 2716   2971  6571.16
## 3:   9    1     233.6494 -0.01645265 0.983      NA 4336   4591  8191.16
## 4:  12    1     263.5635 -0.01672527 0.982      NA 5956   6211  9811.16
## 5:  13    1     230.8041 -0.01273606 0.953      NA 6496   6751 10351.16
## 6:  14    1     243.8418 -0.01327410 0.987      NA 7036   7291 10891.16
##     endtime    oxy endoxy        rate    adjustment rate.adjusted   rate.input
## 1:  6286.16 99.408 95.749 -0.01322641 -0.0009266863  -0.012299721 -0.012299721
## 2:  6826.16 99.100 95.491 -0.01326130 -0.0012535124  -0.012007786 -0.012007786
## 3:  8446.16 98.856 94.367 -0.01645265 -0.0022339907  -0.014218659 -0.014218659
## 4: 10066.16 98.996 95.084 -0.01672527 -0.0032144689  -0.013510806 -0.013510806
## 5: 10606.16 98.779 95.212 -0.01273606 -0.0035412950  -0.009194769 -0.009194769
## 6: 11146.16 99.019 95.614 -0.01327410 -0.0038681211  -0.009405978 -0.009405978
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1430630
## 2:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1396674
## 3:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1653830
## 4:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1571496
## 5:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1069481
## 6:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.1094047
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -264.6864          NA  mgO2/hr/kg   -264.6864
## 2:   -258.4041          NA  mgO2/hr/kg   -258.4041
## 3:   -305.9814          NA  mgO2/hr/kg   -305.9814
## 4:   -290.7486          NA  mgO2/hr/kg   -290.7486
## 5:   -197.8688          NA  mgO2/hr/kg   -197.8688
## 6:   -202.4139          NA  mgO2/hr/kg   -202.4139
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 2 CVLA486 CVLA463 Vlassof 216 0.0005405 ch3 Dell7440 0.04977 2023-06-28 2024-08-16 good/good 36 27 264.4469 0.1429335 0.9822

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.49
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,  
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]   2   3   4   5  14  15  16 114 115 118 119 120 125 126 127 130 131 132 134
## [20] 135
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.11
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     224.6574 -0.03720794 0.9953575      NA   123    183
##   2:    NA     2     224.6438 -0.03720238 0.9953165      NA   125    185
##   3:    NA     3     224.5759 -0.03718379 0.9952406      NA   124    184
##   4:    NA     4     224.4576 -0.03715285 0.9951354      NA   119    179
##   5:    NA     5     224.4415 -0.03714764 0.9951190      NA   120    180
##  ---                                                                    
## 237:    NA   237     196.2324 -0.02894042 0.9834175      NA    16     76
## 238:    NA   238     196.2044 -0.02893175 0.9834315      NA    15     75
## 239:    NA   239     196.0702 -0.02889540 0.9831522      NA    19     79
## 240:    NA   240     195.8123 -0.02881724 0.9837630      NA    17     77
## 241:    NA   241     195.7889 -0.02881148 0.9838087      NA    18     78
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 3473.16 3533.16 95.340 93.240 -0.03720794
##   2: 3475.16 3535.16 95.329 93.203 -0.03720238
##   3: 3474.16 3534.16 95.307 93.265 -0.03718379
##   4: 3469.16 3529.16 95.505 93.411 -0.03715285
##   5: 3470.16 3530.16 95.517 93.369 -0.03714764
##  ---                                          
## 237: 3366.16 3426.16 98.900 97.033 -0.02894042
## 238: 3365.16 3425.16 98.882 97.104 -0.02893175
## 239: 3369.16 3429.16 98.698 96.843 -0.02889540
## 240: 3367.16 3427.16 98.898 97.037 -0.02881724
## 241: 3368.16 3428.16 98.838 96.904 -0.02881148
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.03720794
## Adjustment    : 0.0004699868
## Adjusted Rate : -0.03767793 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 241 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 240 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     224.6574 -0.03720794 0.9953575      NA 123    183 3473.16
##    endtime   oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 3533.16 95.34  93.24 -0.03720794 0.0004699868   -0.03767793 -0.03767793
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0005405   NA 36 27 1.013253 -0.4382472
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -810.8181          NA  mgO2/hr/kg   -810.8181
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 2 CVLA486 CVLA463 Vlassof 216 0.0005405 ch3 Dell7440 0.04977 2023-06-28 2024-08-16 good/good 36 27 264.4469 0.1429335 0.9822 810.8181 0.4382472 0.9953575 546.3712 0.2953136

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 351 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

3

Enter specimen data

Replicate = 3 
mass = 0.0006386 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "28 June 2023 12 42PM/Oxygen"
experiment_mmr_date2 <- "28 June 2023 12 42PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0008928966

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post
## [1] -0.003442965

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.49
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1] 10 11 14 15 16 18 19 23 24 29 30 31 32 33 36 37 38 39 40 41
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.17
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density   row endrow     time
## 1:  14    1     413.5846 -0.02893900 0.989      NA  7066   7321 10921.16
## 2:  15    1     426.6988 -0.02872706 0.994      NA  7606   7861 11461.16
## 3:  16    1     419.6620 -0.02688908 0.994      NA  8146   8401 12001.16
## 4:  17    1     471.1060 -0.02980015 0.999      NA  8686   8941 12541.16
## 5:  18    1     482.7342 -0.02941845 0.991      NA  9226   9481 13081.16
## 6:  21    1     509.1178 -0.02800559 0.995      NA 10846  11101 14701.16
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 11176.16 97.966 90.177 -0.02893900 -0.001918640   -0.02702036 -0.02702036
## 2: 11716.16 97.405 90.379 -0.02872706 -0.002129574   -0.02659749 -0.02659749
## 3: 12256.16 97.144 89.999 -0.02688908 -0.002340508   -0.02454857 -0.02454857
## 4: 12796.16 97.481 89.745 -0.02980015 -0.002551442   -0.02724871 -0.02724871
## 5: 13336.16 98.113 90.874 -0.02941845 -0.002762375   -0.02665608 -0.02665608
## 6: 14956.16 97.338 90.075 -0.02800559 -0.003395177   -0.02461041 -0.02461041
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2900361
## 2:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2854970
## 3:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2635040
## 4:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2924872
## 5:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2861259
## 6:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.2641678
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -454.1749          NA  mgO2/hr/kg   -454.1749
## 2:   -447.0670          NA  mgO2/hr/kg   -447.0670
## 3:   -412.6276          NA  mgO2/hr/kg   -412.6276
## 4:   -458.0132          NA  mgO2/hr/kg   -458.0132
## 5:   -448.0518          NA  mgO2/hr/kg   -448.0518
## 6:   -413.6670          NA  mgO2/hr/kg   -413.6670
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 3 CVLA486 CVLA463 Vlassof 216 0.0006386 ch2 Dell7440 0.04593 2023-06-28 2024-08-16 good/good 36 27 444.1948 0.2836628 0.9936

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.49
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1] 10 11 14 15 16 18 19 23 24 29 30 31 32 33 36 37 38 39 40 41
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.93 1.17
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0     slope_b1       rsq density   row endrow
##      <num> <int>        <num>        <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     359.5512 -0.066031759 0.9600967      NA   205    265
##   2:    NA     2     359.1746 -0.065942317 0.9595820      NA   204    264
##   3:    NA     3     359.1703 -0.065935889 0.9595322      NA   206    266
##   4:    NA     4     358.5142 -0.065772462 0.9584608      NA   207    267
##   5:    NA     5     358.2194 -0.065711475 0.9582123      NA   203    263
##  ---                                                                     
## 237:    NA   237     114.9990 -0.004681025 0.6492999      NA    28     88
## 238:    NA   238     114.9436 -0.004667529 0.6643042      NA    24     84
## 239:    NA   239     113.9089 -0.004402750 0.6324622      NA    25     85
## 240:    NA   240     113.7635 -0.004365122 0.6240093      NA    27     87
## 241:    NA   241     113.4991 -0.004297642 0.6155449      NA    26     86
##         time endtime    oxy endoxy         rate
##        <num>   <num>  <num>  <num>        <num>
##   1: 4060.16 4120.16 91.093 87.784 -0.066031759
##   2: 4059.16 4119.16 91.091 87.811 -0.065942317
##   3: 4061.19 4121.19 91.079 87.797 -0.065935889
##   4: 4062.16 4122.16 91.002 87.809 -0.065772462
##   5: 4058.16 4118.16 91.110 87.832 -0.065711475
##  ---                                           
## 237: 3883.16 3943.16 96.819 96.431 -0.004681025
## 238: 3879.16 3939.16 96.901 96.614 -0.004667529
## 239: 3880.16 3940.16 96.818 96.654 -0.004402750
## 240: 3882.16 3942.16 96.741 96.548 -0.004365122
## 241: 3881.16 3941.16 96.787 96.631 -0.004297642
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.06603176
## Adjustment    : 0.0008928966
## Adjusted Rate : -0.06692466 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 145 rate(s) removed, 96 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 95 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     359.5512 -0.06603176 0.9600967      NA 205    265 4060.16
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 4120.16 91.093 87.784 -0.06603176 0.0008928966   -0.06692466 -0.06692466
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0006386   NA 36 27 1.013253 -0.7183681
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1124.911          NA  mgO2/hr/kg   -1124.911
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 3 CVLA486 CVLA463 Vlassof 216 0.0006386 ch2 Dell7440 0.04593 2023-06-28 2024-08-16 good/good 36 27 444.1948 0.2836628 0.9936 1124.911 0.7183681 0.9600967 680.7162 0.4347054

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 352 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

5

Enter specimen data

Replicate = 5 
mass = 0.0006779
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "28 June 2023 01 06PM/Oxygen"
experiment_mmr_date2_asus <- "28 June 2023 01 06PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001261271

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------
## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.003061851

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2_asus$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   9    1     328.6820 -0.02115800 0.985      NA 3189   3377 10818.95
## 2:  10    1     319.2929 -0.01932757 0.968      NA 3587   3774 11359.30
## 3:  12    1     364.2349 -0.02128754 0.994      NA 4382   4570 12439.12
## 4:  13    1     362.1198 -0.02022964 0.990      NA 4780   4968 12978.59
## 5:  14    1     408.6373 -0.02285054 0.986      NA 5178   5366 13518.58
## 6:  19    1     438.7015 -0.02094715 0.982      NA 7167   7355 16219.02
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 11073.98 99.278 94.114 -0.02115800 -0.002001688   -0.01915631 -0.01915631
## 2: 11613.87 99.196 94.325 -0.01932757 -0.002287491   -0.01704008 -0.01704008
## 3: 12693.77 98.980 93.785 -0.02128754 -0.002858894   -0.01842864 -0.01842864
## 4: 13233.27 99.076 94.055 -0.02022964 -0.003144360   -0.01708528 -0.01708528
## 5: 13773.38 99.269 93.642 -0.02285054 -0.003430125   -0.01942041 -0.01942041
## 6: 16474.70 99.011 93.939 -0.02094715 -0.004859285   -0.01608786 -0.01608786
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.2144878
## 2:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.1907930
## 3:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.2063403
## 4:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.1912991
## 5:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.2174448
## 6:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.1801312
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -316.4003          NA  mgO2/hr/kg   -316.4003
## 2:   -281.4471          NA  mgO2/hr/kg   -281.4471
## 3:   -304.3816          NA  mgO2/hr/kg   -304.3816
## 4:   -282.1936          NA  mgO2/hr/kg   -282.1936
## 5:   -320.7624          NA  mgO2/hr/kg   -320.7624
## 6:   -265.7194          NA  mgO2/hr/kg   -265.7194
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 5 CVLA486 CVLA463 Vlassof 216 0.0006779 ch4 Asus 0.04791 2023-06-28 2024-08-16 good/good 36 27 301.037 0.204073 0.9846

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.59
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8  9 10 12 13 14 15 16 17 18 19 20 21 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.41
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     418.4397 -0.06474784 0.9824441      NA   111    156
##   2:    NA     2     417.6107 -0.06458356 0.9820007      NA   110    155
##   3:    NA     3     417.1083 -0.06448083 0.9817736      NA   112    157
##   4:    NA     4     416.7588 -0.06441529 0.9813631      NA   109    154
##   5:    NA     5     415.5185 -0.06416966 0.9802861      NA   108    153
##  ---                                                                    
## 173:    NA   173     174.0484 -0.01544184 0.8742584      NA     6     51
## 174:    NA   174     172.9868 -0.01522932 0.8751348      NA    10     55
## 175:    NA   175     172.8022 -0.01518682 0.8773453      NA     7     52
## 176:    NA   176     172.6780 -0.01516409 0.8770815      NA     9     54
## 177:    NA   177     172.2989 -0.01508464 0.8789805      NA     8     53
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 4976.90 5036.90 96.075 92.419 -0.06474784
##   2: 4975.54 5035.54 96.078 92.576 -0.06458356
##   3: 4978.26 5038.26 96.107 92.420 -0.06448083
##   4: 4974.20 5034.20 96.096 92.674 -0.06441529
##   5: 4972.87 5032.87 96.109 92.807 -0.06416966
##  ---                                          
## 173: 4834.34 4894.34 99.658 98.462 -0.01544184
## 174: 4839.74 4899.74 99.487 98.158 -0.01522932
## 175: 4835.70 4895.70 99.570 98.387 -0.01518682
## 176: 4838.38 4898.38 99.482 98.214 -0.01516409
## 177: 4837.05 4897.05 99.517 98.317 -0.01508464
## 
## Regressions : 177 | Results : 177 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 177 adjusted rate(s):
## Rate          : -0.06474784
## Adjustment    : 0.001261271
## Adjusted Rate : -0.06600911 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 61 rate(s) removed, 116 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 115 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow   time
## 1:  NA    1     418.4397 -0.06474784 0.9824441      NA 111    156 4976.9
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1:  5036.9 96.075 92.419 -0.06474784 0.001261271   -0.06600911 -0.06600911
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.0006779   NA 36 27 1.013253 -0.7390853
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1090.257          NA  mgO2/hr/kg   -1090.257
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 5 CVLA486 CVLA463 Vlassof 216 0.0006779 ch4 Asus 0.04791 2023-06-28 2024-08-16 good/good 36 27 301.037 0.204073 0.9846 1090.257 0.7390853 0.9824441 789.2201 0.5350123
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 353 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

6

Enter specimen data

Replicate = 6 
mass = 0.0006426
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "28 June 2023 01 24PM/Oxygen"
experiment_mmr_date2_asus <- "28 June 2023 01 24PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0002724519

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.002213646

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  13    1     366.6624 -0.02059642 0.980      NA 4780   4961 12978.59
## 2:  16    1     349.2840 -0.01715498 0.997      NA 5975   6155 14599.40
## 3:  17    1     406.2360 -0.02027165 0.988      NA 6372   6553 15138.51
## 4:  18    1     344.2307 -0.01565134 0.956      NA 6770   6950 15678.63
## 5:  20    1     472.1031 -0.02227926 0.987      NA 7564   7744 16758.75
## 6:  21    1     443.0141 -0.01990441 0.986      NA 7961   8141 17298.94
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 13223.81 98.983 93.881 -0.02059642 -0.002249571   -0.01834685 -0.01834685
## 2: 14844.32 98.696 94.478 -0.01715498 -0.002634640   -0.01452034 -0.01452034
## 3: 15384.21 98.929 94.105 -0.02027165 -0.002762825   -0.01750882 -0.01750882
## 4: 15923.47 98.793 94.253 -0.01565134 -0.002891056   -0.01276028 -0.01276028
## 5: 17003.75 98.426 92.921 -0.02227926 -0.003147711   -0.01913155 -0.01913155
## 6: 17543.84 98.315 93.487 -0.01990441 -0.003276049   -0.01662836 -0.01662836
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.1951340
## 2:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.1544358
## 3:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.1862208
## 4:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.1357162
## 5:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.2034799
## 6:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.1768564
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -303.6632          NA  mgO2/hr/kg   -303.6632
## 2:   -240.3296          NA  mgO2/hr/kg   -240.3296
## 3:   -289.7928          NA  mgO2/hr/kg   -289.7928
## 4:   -211.1985          NA  mgO2/hr/kg   -211.1985
## 5:   -316.6509          NA  mgO2/hr/kg   -316.6509
## 6:   -275.2200          NA  mgO2/hr/kg   -275.2200
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 6 CVLA486 CVLA463 Vlassof 216 0.0006426 ch3 Asus 0.04551 2023-06-28 2024-08-16 good/good 36 27 285.1313 0.1832254 0.9876

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.06
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row,
              to = cycle1.end.row,
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.69
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     466.6540 -0.06073692 0.9665856      NA   165    210
##   2:    NA     2     465.7531 -0.06058527 0.9699428      NA   168    213
##   3:    NA     3     465.3776 -0.06052172 0.9694320      NA   169    214
##   4:    NA     4     464.6481 -0.06040990 0.9685991      NA   167    212
##   5:    NA     5     463.1442 -0.06016980 0.9669375      NA   166    211
##  ---                                                                    
## 172:    NA   172     195.6077 -0.01684024 0.9536978      NA   100    145
## 173:    NA   173     194.6612 -0.01668327 0.9533811      NA    96    141
## 174:    NA   174     194.6136 -0.01667716 0.9543983      NA    99    144
## 175:    NA   175     193.9152 -0.01656228 0.9555105      NA    98    143
## 176:    NA   176     193.9042 -0.01655999 0.9554822      NA    97    142
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 6167.70 6227.70 91.661 88.561 -0.06073692
##   2: 6171.76 6231.76 91.457 88.548 -0.06058527
##   3: 6173.10 6233.10 91.426 88.563 -0.06052172
##   4: 6170.42 6230.42 91.550 88.554 -0.06040990
##   5: 6169.07 6229.07 91.611 88.585 -0.06016980
##  ---                                          
## 172: 6079.14 6139.14 93.263 92.143 -0.01684024
## 173: 6073.72 6133.72 93.514 92.284 -0.01668327
## 174: 6077.78 6137.78 93.320 92.159 -0.01667716
## 175: 6076.42 6136.42 93.366 92.216 -0.01656228
## 176: 6075.07 6135.07 93.456 92.236 -0.01655999
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.06073692
## Adjustment    : -0.0002724519
## Adjusted Rate : -0.06046447 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 33 rate(s) removed, 143 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 142 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow   time
## 1:  NA    1      466.654 -0.06073692 0.9665856      NA 165    210 6167.7
##    endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  6227.7 91.661 88.561 -0.06073692 -0.0002724519   -0.06046447 -0.06046447
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04551 0.0006426   NA 36 27 1.013253 -0.6430897
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1000.762          NA  mgO2/hr/kg   -1000.762
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 6 CVLA486 CVLA463 Vlassof 216 0.0006426 ch3 Asus 0.04551 2023-06-28 2024-08-16 good/good 36 27 285.1313 0.1832254 0.9876 1000.762 0.6430897 0.9665856 715.6308 0.4598644
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 354 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

7

Enter specimen data

Replicate = 7 
mass = 0.0007666 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "28 June 2023 01 24PM/Oxygen"
experiment_mmr_date2_asus <- "28 June 2023 01 24PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0009799036

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean) #,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.002329308

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  12    1     398.6377 -0.02417725 0.994      NA 4382   4563 12439.12
## 2:  16    1     480.2455 -0.02615687 0.997      NA 5975   6155 14599.40
## 3:  17    1     500.2066 -0.02652319 0.976      NA 6372   6553 15138.51
## 4:  18    1     469.9335 -0.02368092 0.978      NA 6770   6950 15678.63
## 5:  19    1     481.0213 -0.02359040 0.992      NA 7167   7347 16219.02
## 6:  21    1     517.0030 -0.02422327 0.994      NA 7961   8141 17298.94
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 12684.26 98.057 91.825 -0.02417725 -0.002172025   -0.02200523 -0.02200523
## 2: 14844.32 98.141 92.006 -0.02615687 -0.003046989   -0.02310988 -0.02310988
## 3: 15384.21 97.982 91.861 -0.02652319 -0.003265510   -0.02325768 -0.02325768
## 4: 15923.47 98.344 92.277 -0.02368092 -0.003484109   -0.02019681 -0.02019681
## 5: 16463.76 98.146 92.735 -0.02359040 -0.003702970   -0.01988743 -0.01988743
## 6: 17543.84 97.749 91.685 -0.02422327 -0.004140418   -0.02008285 -0.02008285
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2351752
## 2:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2469809
## 3:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2485604
## 4:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2158482
## 5:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2125418
## 6:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.2146303
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -306.7770          NA  mgO2/hr/kg   -306.7770
## 2:   -322.1771          NA  mgO2/hr/kg   -322.1771
## 3:   -324.2375          NA  mgO2/hr/kg   -324.2375
## 4:   -281.5656          NA  mgO2/hr/kg   -281.5656
## 5:   -277.2526          NA  mgO2/hr/kg   -277.2526
## 6:   -279.9770          NA  mgO2/hr/kg   -279.9770
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 7 CVLA486 CVLA463 Vlassof 216 0.0007666 ch2 Asus 0.04573 2023-06-28 2024-08-16 good/good 36 27 302.9468 0.232239 0.9878

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.06
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.69
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     419.4577 -0.05366074 0.9937052      NA    97    142
##   2:    NA     2     419.2891 -0.05363361 0.9936494      NA    96    141
##   3:    NA     3     418.7834 -0.05354985 0.9935321      NA    98    143
##   4:    NA     4     417.5115 -0.05334322 0.9927825      NA    95    140
##   5:    NA     5     415.9065 -0.05307866 0.9932417      NA    99    144
##  ---                                                                    
## 172:    NA   172     224.2354 -0.02189641 0.9683495      NA   147    192
## 173:    NA   173     224.0547 -0.02186814 0.9717323      NA   149    194
## 174:    NA   174     224.0430 -0.02186720 0.9717290      NA   150    195
## 175:    NA   175     223.8538 -0.02183754 0.9688355      NA   151    196
## 176:    NA   176     222.8165 -0.02166730 0.9705338      NA   148    193
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 6075.07 6135.07 93.458 90.306 -0.05366074
##   2: 6073.72 6133.72 93.411 90.370 -0.05363361
##   3: 6076.42 6136.42 93.426 90.263 -0.05354985
##   4: 6072.36 6132.36 93.469 90.420 -0.05334322
##   5: 6077.78 6137.78 93.474 90.239 -0.05307866
##  ---                                          
## 172: 6143.22 6203.22 89.941 88.385 -0.02189641
## 173: 6145.92 6205.92 89.830 88.256 -0.02186814
## 174: 6147.28 6207.28 89.785 88.177 -0.02186720
## 175: 6148.67 6208.67 89.681 88.149 -0.02183754
## 176: 6144.58 6204.58 89.902 88.336 -0.02166730
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.05366074
## Adjustment    : 0.0009799036
## Adjusted Rate : -0.05464065 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 176 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 175 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     419.4577 -0.05366074 0.9937052      NA  97    142 6075.07
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 6135.07 93.458 90.306 -0.05366074 0.0009799036   -0.05464065 -0.05464065
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0007666   NA 36 27 1.013253 -0.5839579
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -761.7504          NA  mgO2/hr/kg   -761.7504
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 7 CVLA486 CVLA463 Vlassof 216 0.0007666 ch2 Asus 0.04573 2023-06-28 2024-08-16 good/good 36 27 302.9468 0.232239 0.9878 761.7504 0.5839579 0.9937052 458.8036 0.3517188
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 355 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

8

Enter specimen data

Replicate = 8 
mass = 0.0007104 
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "28 June 2023 01 33PM/Oxygen"
experiment_mmr_date2_asus <- "28 June 2023 01 33PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0006639998

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.004602302

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  14    1     530.9498 -0.03215549 0.999      NA 5178   5359 13518.58
## 2:  17    1     550.2460 -0.02990504 0.996      NA 6372   6553 15138.51
## 3:  18    1     531.5604 -0.02771550 0.988      NA 6770   6950 15678.63
## 4:  19    1     536.9191 -0.02712161 0.988      NA 7167   7347 16219.02
## 5:  20    1     624.7216 -0.03148939 0.997      NA 7564   7744 16758.75
## 6:  21    1     630.4792 -0.03086186 0.997      NA 7961   8141 17298.94
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 13763.92 96.261 88.386 -0.03215549 -0.004935515   -0.02721997 -0.02721997
## 2: 15384.21 97.066 89.906 -0.02990504 -0.005716480   -0.02418856 -0.02418856
## 3: 15923.47 96.942 89.763 -0.02771550 -0.005976635   -0.02173886 -0.02173886
## 4: 16463.76 96.725 90.098 -0.02712161 -0.006237102   -0.02088451 -0.02088451
## 5: 17003.75 96.821 89.224 -0.03148939 -0.006497339   -0.02499205 -0.02499205
## 6: 17543.84 96.325 89.070 -0.03086186 -0.006757710   -0.02410415 -0.02410415
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2903976
## 2:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2580568
## 3:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2319221
## 4:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2228073
## 5:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2666289
## 6:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.2571562
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -408.7803          NA  mgO2/hr/kg   -408.7803
## 2:   -363.2556          NA  mgO2/hr/kg   -363.2556
## 3:   -326.4669          NA  mgO2/hr/kg   -326.4669
## 4:   -313.6365          NA  mgO2/hr/kg   -313.6365
## 5:   -375.3221          NA  mgO2/hr/kg   -375.3221
## 6:   -361.9879          NA  mgO2/hr/kg   -361.9879
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
129 8 CVLA486 CVLA463 Vlassof 216 0.0007104 ch1 Asus 0.04565 2023-06-28 2024-08-16 good/good 36 27 367.1626 0.2608323 0.9954

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.25
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row,  
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 11 13 14 15 16 18 20 21 22 24 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.70
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     650.1405 -0.08418235 0.9868592      NA   170    215
##   2:    NA     2     649.8371 -0.08413524 0.9867136      NA   171    216
##   3:    NA     3     648.0031 -0.08386776 0.9857888      NA   169    214
##   4:    NA     4     647.8836 -0.08384374 0.9858130      NA   172    217
##   5:    NA     5     645.4844 -0.08348645 0.9847715      NA   173    218
##  ---                                                                    
## 171:    NA   171     387.5020 -0.04468077 0.9923198      NA    16     61
## 172:    NA   172     385.6541 -0.04439827 0.9925034      NA    17     62
## 173:    NA   173     384.2700 -0.04418718 0.9930816      NA    18     63
## 174:    NA   174     384.2297 -0.04418364 0.9925669      NA    20     65
## 175:    NA   175     382.8101 -0.04396499 0.9941782      NA    19     64
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 6716.50 6776.50 84.366 79.937 -0.08418235
##   2: 6717.84 6777.84 84.326 79.903 -0.08413524
##   3: 6715.15 6775.15 84.383 79.876 -0.08386776
##   4: 6719.19 6779.19 84.325 79.847 -0.08384374
##   5: 6720.57 6780.57 84.290 79.746 -0.08348645
##  ---                                          
## 171: 6505.51 6565.51 96.974 94.196 -0.04468077
## 172: 6506.85 6566.85 96.915 94.128 -0.04439827
## 173: 6508.37 6568.37 96.890 93.987 -0.04418718
## 174: 6511.10 6571.10 96.792 93.619 -0.04418364
## 175: 6509.74 6569.74 96.883 93.867 -0.04396499
## 
## Regressions : 175 | Results : 175 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 175 adjusted rate(s):
## Rate          : -0.08418235
## Adjustment    : -0.0006639998
## Adjusted Rate : -0.08351835 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 175 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 174 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow   time
## 1:  NA    1     650.1405 -0.08418235 0.9868592      NA 170    215 6716.5
##    endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  6776.5 84.366 79.937 -0.08418235 -0.0006639998   -0.08351835 -0.08351835
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04565 0.0007104   NA 36 27 1.013253 -0.8910194
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:    -1254.25          NA  mgO2/hr/kg    -1254.25
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
129 8 CVLA486 CVLA463 Vlassof 216 0.0007104 ch1 Asus 0.04565 2023-06-28 2024-08-16 good/good 36 27 367.1626 0.2608323 0.9954 1254.25 0.8910194 0.9868592 887.0877 0.6301871
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 356 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)